#pragma once

using namespace std;

#include "ProcTable.h"

ProcTable::ProcTable()
{
	count = 0;
};

int ProcTable::getSize()
{		
	return count;
};

INDEX ProcTable::insertProc(NAME procName)
{
	INDEX ret = getProcIndex(procName);
	if(ret==-1)
	{
		++count;
		procTable.insert(std::make_pair<INDEX,NAME>(count,procName)); 
		return count;
	}
	else
	{
		return ret;
	}
};

NAME ProcTable::getProcName(INDEX ind)
{
	unordered_map<INDEX,NAME>::const_iterator got = procTable.find(ind);

	if(got == procTable.end())
	{
		return NULL;
	}
	else
	{
		return got->second;
	}
};

INDEX ProcTable::getProcIndex(NAME procName)
{
	if(procTable.empty())
	{
		return -1;
	}
	for(int i = 1;i<=getSize();i++)
	{
		if(procTable.at(i)==procName) 
		{
			return i;
		}
	}
	return -1;
};

void ProcTable::printProcTable()
{
	for ( auto it = procTable.begin(); it != procTable.end(); ++it )
	{
		cout << it->first << " : " << it->second << endl;
	}
};